/*
============================================================================
FileName	:	XQChatRosterView.cpp
Author		:	liyake
Website		:	http://www.liyake.com
Create Data	:	2012-03-17 11:41
Change Data	:	2012-03-17 11:41 by liyake
Detail		:	The socket client of xqchat application
============================================================================
*/

#include "XQChatRosterView.h"
#include "XQChatClientManager.h"
#include <QtGui>

using namespace XQChat;

XQChat::CXQChatRosterView::CXQChatRosterView( QWidget * parent /*= 0*/ )
	: QGraphicsView(parent)
{
	m_pScene = new CXQChatRosterScene(this);
	m_pScene->setItemIndexMethod(QGraphicsScene::NoIndex);
	m_pScene->setSceneRect(0, -0, 1100, 1100);

	setScene(m_pScene);
	setCacheMode(CacheBackground);
	setViewportUpdateMode(BoundingRectViewportUpdate);
	setRenderHint(QPainter::Antialiasing);
	setTransformationAnchor(AnchorUnderMouse);
	scale(qreal(0.8), qreal(0.8));
	setMinimumSize(400, 400);
	setWindowTitle(tr("Elastic Nodes"));
}

XQChat::CXQChatRosterView::CXQChatRosterView( QGraphicsScene * scene, QWidget * parent /*= 0*/ )
	: QGraphicsView(scene,parent)
{

}

XQChat::CXQChatRosterView::~CXQChatRosterView( void )
{

}

void XQChat::CXQChatRosterView::updateRoster( CXQChatRoster* pRoster )
{
	m_pScene->updateRoster(pRoster);
}

void XQChat::CXQChatRosterView::keyPressEvent( QKeyEvent *event )
{
	QGraphicsView::keyPressEvent(event);
}

void XQChat::CXQChatRosterView::wheelEvent( QWheelEvent *event )
{
	scaleView(pow((double)2, -event->delta() / 240.0));
}

void XQChat::CXQChatRosterView::scaleView( qreal scaleFactor )
{
	qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
	if (factor < 0.07 || factor > 100)
		return;

	scale(scaleFactor, scaleFactor);
}

